package com.lifeng.controller;

import com.lifeng.dto.CommentDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    private static final Logger log = LoggerFactory.getLogger(CommentController.class);
    /**
     * 获取评论列表
     * */
    @RequestMapping("/{id}")
    public List<CommentDto> commentList(@PathVariable("id") String id,Integer pageIndex){
        //模拟产生数据
        List<CommentDto> commentDtos = new ArrayList<>();
        if(pageIndex == null || pageIndex == 1){
            commentDtos.add(
                    CommentDto.builder()
                    .id("1")
                    .author("王麻子")
                    .content("我是谁我在干啥嘞")
                    .dateTims(new Date())
                    .build()
            );
            commentDtos.add(
                    CommentDto.builder()
                            .id("2")
                            .author("张三")
                            .content("接口返回撒娇开回房间")
                            .dateTims(new Date())
                            .build()
            );
            commentDtos.add(
                    CommentDto.builder()
                            .id("3")
                            .author("积极点")
                            .content("爱克发你姐夫就瞌睡")
                            .dateTims(new Date())
                            .build()
            );
        }else{
            commentDtos.add(
                    CommentDto.builder()
                            .id("4")
                            .author("李思")
                            .content("温热温热")
                            .dateTims(new Date())
                            .build()
            );
            commentDtos.add(
                    CommentDto.builder()
                            .id("5")
                            .author("企鹅")
                            .content("美女吧投入和广泛地")
                            .dateTims(new Date())
                            .build()
            );
        }
        return commentDtos;
    }

    @RequestMapping("/save")
    public Map<String,Object> save(String content){
        log.info("收到请求content："+content);
        Map<String,Object> res = new HashMap<>();
        res.put("code",1);
        return res;
    }
}
